<template>
	<div class="page">
		<navbar />
		<!-- 商品栏 -->
		<shopCardLayout :res="statisticsData" />
		<!-- 菜单栏 -->
		<menuLayout />

		<!-- 发布商品 -->
		<div class='submit' @click='pushGoods'>
			发布商品
		</div>
		<!-- 店铺数据 -->
		<shopStatisticsLayout :res="statisticsData" />
		<!-- 店铺促销 -->
		<!-- <shopPromotions /> -->

		<!-- 标签栏 -->
		<tabs @changed="(val)=>{current = val.index}" />
		<!-- 流量统计 -->
		<trafficStatistics v-if="current == 0" />
		<!-- 订单统计 -->
		<orderStatistics v-if="current == 1" />
		<!-- 商品统计 -->
		<goodsStatistics v-if="current == 2" />

	</div>
</template>

<script>
	import shopCardLayout from "@/pages/tabbar/home/template/shop-card"; //店铺卡片
	import menuLayout from "@/pages/tabbar/home/template/menu"; //菜单栏
	import navbar from "@/pages/tabbar/home/template/navbar"; //自定义navbar
	import shopStatisticsLayout from "@/pages/tabbar/home/template/shop-statistics"; //店铺统计
	import trafficStatistics from "@/pages/tabbar/home/template/traffic-statistics"; //流量统计
	import tabs from "@/pages/tabbar/home/template/tabs"; //标签
	import orderStatistics from "@/pages/tabbar/home/template/order-statistics"; //订单统计
	import goodsStatistics from "@/pages/tabbar/home/template/goods-statistics"; //商品统计
	import shopPromotions from "@/pages/tabbar/home/template/promotions"; //商品统计
	import {
		homeStatistics
	} from "@/api/home";
	export default {
		components: {
			menuLayout,
			navbar,
			shopCardLayout,
			shopStatisticsLayout,
			trafficStatistics,
			orderStatistics,
			goodsStatistics,
			shopPromotions,
			tabs,
		},
		data() {
			return {
				statisticsData: "", //统计数据
				current: 0, //tab的索引值 默认为流量统计
			};
		},
		/**
		 * 加载的时候通知子级加载
		 */
		onShow() {
			uni.$emit("onShow");
		},
		onPullDownRefresh() {
			this.init();
		},

		mounted() {
			this.init();
		},
		methods: {
			toJSON(){
				return this
			},
			// 发布商品
			pushGoods() {
				uni.navigateTo({
					url:'/pages/goods/goodsOperation'
				})
			},
			// 初始化首页数据
			init() {
				this.getStoreStatistics();
			},
			// 获取店铺统计
			async getStoreStatistics() {
				uni.stopPullDownRefresh()
				let res = await homeStatistics();
				if (res.data.success) {
					this.statisticsData = res.data.result;
				}
			},
		},
	};
</script>

<style scoped lang="scss">
	@import "./template/styles.scss";

	.page {
		padding-bottom: 100rpx;
	}

	.submit {
		margin: 20rpx 32rpx;
	}
</style>
